const { logger } = require("../config/logConfig")

const Comment = require("../models/Comment")
/**
 * 获取文章评论列表, 此接口用于前台PC端 故需要对 
 * @param {*} req
 * @param {req.artcile_id} 文章ID  
 * @param {*} res 
 */
async function commentList (req, res) {
  let condition = utils.completeSelect(req.body)
  let pageObj = utils.pageSelect(req.body)
  try {
    const comment = await Comment.findAndCountAll({
      offset: pageObj.skip,
      limit: pageObj.limit,
      where: {
        condition
      },
      distinct: true
    })
    if (!comment) {
      utils.responseContent(res, 'OK', 200, data = { list: [], total: 0, pageSize: 10, pageNum: 1 })
    }
    utils.responseContent(res, 'OK', 200, data = {
      list: comment.row,
      pageNum: (pageObj.skip / pageObj.limit) + 1,
      pageSize: pageObj.limit,
      total: comment.count
    })
  } catch (error) {
    
  }
}
module.exports = { commentList }
